package edu.hawaii.solardecathlon.page.admin;

import java.util.Map;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;
import edu.hawaii.solardecathlon.page.BasePage;

/**
 * Admin page for Solar Decathlon.
 * 
 * @author Harry Kwan
 */
public class AdminPage extends BasePage {

  /** Support serialization. */
  private static final long serialVersionUID = 1L;

  /**
   * Creates the admin page for home management.
   */
  public AdminPage() {
    // Get the properties stored in the session.
    Map<String, String> props = getSessionProperties("admin");

    // local login info
    Form<String> admin = new Form<String>("localLogin");
    admin.add(new TextField<String>("local_user", new PropertyModel<String>(props, "local_user"))
        .setType(String.class));
    admin.add(new PasswordTextField("local_pass1", new PropertyModel<String>(props, "local_pass1"))
        .setType(String.class));
    admin.add(new PasswordTextField("local_pass2", new PropertyModel<String>(props, "local_pass2"))
        .setType(String.class));
    admin.add(new TextField<String>("local_ip", new PropertyModel<String>(props, "local_ip"))
        .setType(String.class));
    admin.add(new TextField<String>("local_port", new PropertyModel<String>(props, "local_port"))
        .setType(String.class));
    admin.add(new TextField<String>("hostname", new PropertyModel<String>(props, "hostname"))
        .setType(String.class));

    // remote login info
    admin.add(new CheckBox("remote_check"));
    admin.add(new TextField<String>("remote_user", new PropertyModel<String>(props, "remote_user"))
        .setType(String.class));
    admin.add(new PasswordTextField("remote_pass1",
        new PropertyModel<String>(props, "remote_pass1")).setType(String.class));
    admin.add(new PasswordTextField("remote_pass2",
        new PropertyModel<String>(props, "remote_pass2")).setType(String.class));
    admin.add(new TextField<String>("remote_port", new PropertyModel<String>(props, "remote_port"))
        .setType(String.class));

    // services info
    admin.add(new TextField<String>("energyserv", new PropertyModel<String>(props, "energyserv"))
        .setType(String.class));
    admin.add(new TextField<String>("lightingserv",
        new PropertyModel<String>(props, "lightingserv")).setType(String.class));
    admin.add(new TextField<String>("coolingserv", new PropertyModel<String>(props, "coolingserv"))
        .setType(String.class));
    admin.add(new TextField<String>("waterserv", new PropertyModel<String>(props, "waterserv"))
        .setType(String.class));
    admin.add(new TextField<String>("aquapondserv",
        new PropertyModel<String>(props, "aquapondserv")).setType(String.class));
    admin.add(new TextField<String>("mediaserv", new PropertyModel<String>(props, "mediaserv"))
        .setType(String.class));
    admin.add(new TextField<String>("voiceserv", new PropertyModel<String>(props, "voiceserv"))
        .setType(String.class));
    admin.add(new TextField<String>("securityserv",
        new PropertyModel<String>(props, "seucrityserv")).setType(String.class));

    // server statuses, not going to implement for now
    // admin.add(new Label("energystat", props.get("energystat")));
    // admin.add(new Label("lightingstat", props.get("lightingstat")));
    // admin.add(new Label("coolingstat", props.get("coolingstat")));
    // admin.add(new Label("waterstat", props.get("waterstat")));
    // admin.add(new Label("aquapondstat", props.get("aquapondstat")));
    // admin.add(new Label("mediastat", props.get("mediastat")));
    // admin.add(new Label("voicestat", props.get("voicestat")));
    // admin.add(new Label("securitystat",props.get("securitystat")));

    admin.add(new CheckBox("lighting_check"));
    admin.add(new CheckBox("cooling_check"));
    admin.add(new CheckBox("water_check"));
    admin.add(new CheckBox("voice_check"));
    admin.add(new CheckBox("media_check"));
    admin.add(new CheckBox("reset_check"));

    // Add the form, providing a submit button with a behavior to redisplay this page.
    admin.add(new Button("submit") {
      private static final long serialVersionUID = 1L;

      /** Save settings and display the page again. */
      @Override
      public void onSubmit() {
        setResponsePage(AdminPage.class);
      }
    });

    // Add the form to this page.
    add(admin);
  }

}
